package twice.class_digui;

public class Class01_Hannuota {
    public static void Hannuota1(int n){
        leftToRigth(n);
    }
    public static void leftToRigth(int N){
        if(N==1){
            System.out.println("Move " + N + " from left to right");
        }
        if(N>1){
            leftToMiddle(N-1);
            System.out.println("Move " + N + " from left to right");
            midleToRigth(N-1);
        }
    }

    public static void leftToMiddle(int N){
        if(N==1){
            System.out.println("Move " + N + " from left to mid");
        }
        if(N>1){
            leftToRigth(N-1);
            System.out.println("Move " + N + " from left to mid");
            rightToMiddle(N-1);
        }
    }

    public static void midleToRigth(int N){
        if(N==1){
            System.out.println("Move " + N + " from mid to right");
        }
        if(N>1){
            middleToLeft(N-1);
            System.out.println("Move " + N + " from mid to right");
            leftToRigth(N-1);
        }
    }

    public static void rightToMiddle(int N){
        if(N==1){
            System.out.println("Move " + N + " from right to mid");
        }
        if(N>1){
            rightToLeft(N-1);
            System.out.println("Move " + N + " from right to mid");
            leftToMiddle(N-1);
        }
    }


    public static void middleToLeft(int N){
        if(N==1){
            System.out.println("Move " + N + " from mid to left");
        }
        if(N>1){
            midleToRigth(N-1);
            System.out.println("Move " + N + " from mid to left");
            rightToLeft(N-1);
        }
    }


    public static void hannota2(int N){
        fromToto(N,"left","right","mid");
    }

    public static void fromToto(int N, String from, String to, String other){
        if(N==1){
            System.out.println("Move " + N + " from "+from+ "to "+to);
        }
        if(N>1){
            fromToto(N-1,from,other,to);
            System.out.println("Move " + N + " from mid to left");
            fromToto(N-1,other,to,from);
        }
    }


    public static void rightToLeft(int N){
        if(N==1){
            System.out.println("Move " + N + " from right to left");
        }
        if(N>1){
            rightToMiddle(N-1);
            System.out.println("Move " + N + " from right to left");
            middleToLeft(N-1);
        }
    }

    public static void main(String[] args) {
        Hannuota1(3);
        System.out.println("================");
        hannota2(3);
    }
}
